package com.org.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.org.pojo.Community;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * ClassName: CommunityMapper
 * Package: com.org.mapper
 * Description:
 *
 * @Author Origin
 * @Create 2024/2/2 10:20
 * @Version 1.0
 */

@Mapper
public interface CommunityMapper extends BaseMapper<Community> {

    @Select("select * from community where province=#{province} AND city=#{city} AND district_or_country=#{districtOrCountry}" +
            " AND name=#{name}")
    Community findByLocationAndName(Community community);



    @Insert("insert into community(province, city, district_or_country, name, create_user_id, state, create_time, update_time) " +
            "values(#{province}, #{city}, #{districtOrCountry}, #{name}, #{createUserId}, #{state}, #{createTime}, #{updateTime})")
    void add(Community community);

    @Select("select * from community where id = #{id}")
    Community getById(Integer id);

    @Update("update community set province=#{province}, city=#{city}, district_or_country=#{districtOrCountry}, name=#{name}, `describe`=#{describe}, " +
            "describeImg01=#{describeImg01}, describeImg02=#{describeImg02}, describeImg03=#{describeImg03}, describeImg04=#{describeImg04}, update_time=#{updateTime} " +
            " where id=#{id}")
    void update(Community community);

    @Update("update community set state=#{state}, update_time=now() where id=#{communityId}")
    void updateState(String state, Integer communityId);

    @Select("select * from community where create_user_id = #{createUserId}")
    Community getByCreateId(Integer createUserId);
}
